# coding: utf8
# try something like
def index(): return dict(message="hello from fav.py")

def add():
     if request.post_vars: 
        vars = request.post_vars
        q1 = db.users.id == vars.user_id
        q2 = db.places.long == vars.long
        q3 = db.places.lat == vars.lat
        #note that place is one row
        place =  db(q2 & q3).select().first
        #note that place is one row
        user =  db(q1).select().first
        db.fav_places.insert(user = user ,place = place )
        return T("favourtie added")
def user_fav_places():
    if request.post_vars: 
        vars = request.post_vars
        q1 = db.users.id == vars.user_id
     
        #note that place is one row
        user =  db(q1).select().first
        #we compare one row with anther
        place = db(db.fav_places.user == user).select()         

        return SQLTABLE(place)
    else:
        return dict()

def users_fav_place():
    if request.post_vars: 
        vars = request.post_vars
       
        q2 = db.places.long == vars.long
        q3 = db.places.lat == vars.lat
        #note that place is one row
        place =  db(q2 & q3).select().first
        #we compare one row with anther
        users = db(db.fav_places.place == place).select()         
    #need test
        return SQLTABLE(users)
    else:
        return dict()
